package com.ryskoo.framework.core.bean;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 查询条件封装,将前端查询条件以及查询的值封装进行整体请求
 *
 * @author ruiyun
 *
 */
public class QueryMessageDTO implements Serializable {
    /**
     * 是否分页查询
     * 默认分页查询，设置为false强制不分页查询
     */
    private boolean byPage = true;

    /**
     * 当前请求的页数
     */
	private int queryPage = 1;

	/** 当前请求每页数量 */
	private int pageShow = 10;

    /** key:字段名称 value:字段值，由于有between的查询条件，需要有2个值，由于有in,notin,可以有多个值 */
    private Map<String, Map<String, Object>> queryParams = new HashMap<String, Map<String, Object>>();

    /** 排序的map,可以进行多组排序，key:字段名，value，排序类型(asc ,desc) */
	private Map<String, String> sortMap = new HashMap<String, String>();

    /** 简易查询用，只需要key和value，后台会手动拆出来判断，用于多表查询附带不同表条件时 */
	private Map<String,Object> simpleQueryParams = new HashMap<String, Object>();

	public void addCondition(String name, String operation, Object value) {
		Map<String, Object> param = new HashMap<>();
		param.put("operation", operation);
		param.put("value", value);
		this.queryParams.put(name, param);
	}

    public void addSort(String name, String orderBy) {
        this.sortMap.put(name, orderBy);
    }

    public boolean isByPage() {
        return byPage;
    }

    public void setByPage(boolean byPage) {
        this.byPage = byPage;
    }

	public int getQueryPage() {
		return queryPage;
	}

	public void setQueryPage(int queryPage) {
		this.queryPage = queryPage;
	}

	public int getPageShow() {
		return pageShow;
	}

	public void setPageShow(int pageShow) {
		this.pageShow = pageShow;
	}

    public Map<String, Map<String, Object>> getQueryParams() {
        return queryParams;
    }

    public void setQueryParams(Map<String, Map<String, Object>> queryParams) {
        this.queryParams = queryParams;
    }

    public Map<String, String> getSortMap() {
		return sortMap;
	}

	public void setSortMap(Map<String, String> sortMap) {
		this.sortMap = sortMap;
	}

	public int getStartNum() {
		return (this.getQueryPage() - 1) * this.pageShow;
	}

	public Map<String, Object> getSimpleQueryParams() {
		return simpleQueryParams;
	}

	public void setSimpleQueryParams(Map<String, Object> simpleQueryParams) {
		this.simpleQueryParams = simpleQueryParams;
	}
	
}
